/**
 * 
 */
package com.laozhao.EasySales.view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRootPane;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;

import com.laozhao.dreamframe.util.ToolsUtil;
import com.laozhao.EasySales.business.SystemServer;
import com.sun.awt.AWTUtilities;

/**
 * @author laozhao
 *
 */
public class StarLoginUI extends JFrame {
	
	JLabel userNameLb;
	protected JTextField userNameTx;
	JLabel passWorld;
	protected JPasswordField passWorldPx;
	protected JButton okButton;

	protected JPanel mesPanel;
	protected JPanel buttonPanel;
	ImageIcon img ;

	//server
	protected SystemServer sys;
	/**
	 * 
	 */
	public StarLoginUI() {
		super();
	}
	
	public void init(){
		//初始化值
		sys = new SystemServer();
		img = new ImageIcon(ToolsUtil.getRoot() + "\\img\\login.jpg");
//		AWTUtilities.setWindowOpaci(this, sys.getFdiaphanous());// 设置窗体的透明度v
		//初始化界面
		initComponents();
		
	}

	private void initComponents() {
		
		int width = img.getIconWidth();
		int hight = img.getIconHeight();
		
		
		mesPanel = new JPanel(new GridLayout(2,2,10,10));
//		mesPanel.setAutoscrolls(false);
		mesPanel.setMaximumSize(new Dimension(20,20));
		mesPanel.setMinimumSize(new Dimension(20,20));
		mesPanel.setSize(new Dimension(50,60));
		Border border = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
//		BorderFactory.createTitledBorder(border ,"标题");
		mesPanel.setBorder(border);
		
		userNameLb = new JLabel("用户名");
		userNameTx = new JTextField();
		userNameTx.setText("admin");
		passWorld = new JLabel("密码");
		passWorldPx = new JPasswordField();
		passWorldPx.setText("admin");
		okButton = new JButton("登陆");
		
		mesPanel.add(userNameLb);
		mesPanel.add(userNameTx);
		mesPanel.add(passWorld);
		mesPanel.add(passWorldPx);
		mesPanel.setOpaque(false);

		FlowLayout fl = new FlowLayout();
		buttonPanel = new JPanel();
		buttonPanel.setLayout(fl);
		buttonPanel.add(okButton);
		//透明色
//		buttonPanel.setBackground(new Color(1.0F, 0.75F, 0.0F, 0.45F));
		//设置面板透明
		buttonPanel.setOpaque(false);
		
		JPanel con = new JPanel(){
			protected void paintComponent(Graphics g){
				//添加画面
				g.drawImage(img.getImage() ,0,0,null);
				super.paintComponent(g);
			}
		};
		con.setLayout(new BorderLayout());
		con.add(mesPanel,BorderLayout.CENTER);
		con.add(buttonPanel,BorderLayout.SOUTH);
		con.setOpaque(false);
		con.repaint();
		
		this.getContentPane().setLayout(new BorderLayout());
		this.getContentPane().add(con,BorderLayout.CENTER);

	    this.setSize(width + 10, hight+30);
//		this.setLocation(sys.getX_POINT()-getWidth()/2, (sys.getY_POINT() - getHeight()/2));

		this.setUndecorated(true); 
		this.getRootPane().setWindowDecorationStyle(JRootPane.QUESTION_DIALOG);
		this.setTitle("登陆");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	
}
